package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.pojo.dto.CinemaHallAddNewDTO;
import cn.tedu.eb_film.pojo.dto.CinemaHallUpdateDTO;
import cn.tedu.eb_film.pojo.vo.CinemaHallListVO;
import cn.tedu.eb_film.pojo.vo.CinemaHallStandardVO;
import cn.tedu.eb_film.pojo.vo.CinemaStandardVO;
import cn.tedu.eb_film.service.CinemaHallService;
import cn.tedu.eb_film.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cinemaHall")
@Slf4j
public class CinemaHallController {
    @Autowired
    CinemaHallService cinemaHallService;

    /**
     * 新增影厅
     * @return
     */
    @PostMapping("/insert")
    public JsonResult<Void> addNewCinemallHall(CinemaHallAddNewDTO cinemaHallAddNewDTO){
        log.debug("开始处理[新增影厅],参数:{}",cinemaHallAddNewDTO);
        cinemaHallService.addNew(cinemaHallAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/delete")
    public JsonResult<Void> deleteCinemaHall(@PathVariable Long id){
        log.debug("开始处理[逻辑删除影厅],参数影院id:{}",id);
        cinemaHallService.deleteOnLogic(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id){
        log.debug("开始处理[启用影厅],参数影院id:{}",id);
        cinemaHallService.setEnable(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    public JsonResult<Void> update(CinemaHallUpdateDTO cinemaHallUpdateDTO){
        log.debug("开始处理[修改影厅],参数:{}",cinemaHallUpdateDTO);
        cinemaHallService.updateById(cinemaHallUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id}")
    public JsonResult<CinemaHallStandardVO> update(@PathVariable Long id){
        log.debug("开始处理[查询影厅],参数id:{}",id);
        CinemaHallStandardVO standardVO = cinemaHallService.getStandardById(id);
        return JsonResult.ok(standardVO);
    }

    @PostMapping("/{id}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id){
        log.debug("开始处理[禁用影厅],参数影院id:{}",id);
        cinemaHallService.setDisable(id);
        return JsonResult.ok();
    }

    @GetMapping("/{cinemaId}/list")
    public JsonResult<List<CinemaHallListVO>> listByCinemaId(@PathVariable Long cinemaId){
        log.debug("开始处理[根据影厅查询影院],参数影院id:{}",cinemaId);
        List<CinemaHallListVO> list = cinemaHallService.listByCinemaId(cinemaId);
        return JsonResult.ok(list);
    }
}
